<template>
  <div>
    <!-- 评估历史弹窗 -->
    <el-dialog
      title="查看历史"
      append-to-body
      :visible.sync="staffphysicalexamiRecordDialog"
      :close-on-click-modal="false"
      :before-close="handleCloseStaffphysicalexamiRecord"
      width="60%"
      heigh="60%"
    >
      <div>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   plain
                   @click="handleDelete">删 除
        </el-button>
      </div>

      <!-- 表格内容 -->
      <avue-crud
        :option="option"
        :table-loading="loading"
        :data="data"
        :page.sync="page"
        v-model="form"
        ref="crud"
        @row-del="rowDel"
        @selection-change="selectionChange"
        @current-change="currentChange"
        @size-change="sizeChange"
        @on-load="onLoad">
      </avue-crud>

      <template slot-scope="scope" slot="menuForm">
      <el-button type="danger"
                 size="small"
                 icon="el-icon-delete"
                 plain
                 @click="handleDelete">删 除
      </el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script>
  import {remove,getList} from "@/api/basedata/occupationalhazards/staffphysicalexamirecord";

  export default {
    props: {
      staffphysicalexamiRecordDialog: {default: false},
      selectTJRYId: {default: ""}
    },
    data() {
      return {
        form: {},
        query: {},
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        selectionList: [],
        option: {
          calcHeight: 30,
          tip: false,
          selection: true,
          border: true,
          addBtn: false,
          delBtn: true,
          viewBtn: true,
          editBtn: false,
          index: true,
          refreshBtn: false,
          columnBtn: false,
          menu: true,
          column: [
            {
              label: "体检类型",
              prop: "tjlx",
              align: "center",
              type: "select",
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=types_of_exami",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: true,
                message: "请输入体检类型",
                trigger: "blur"
              }]
            },
            {
              label: "员工姓名",
              prop: "ygxm",
              align: "center",
              hide: true,
              row: false,
              display: false,
            },
            {
              label: "身份证号",
              prop: "sfzh",
              align: "center",
              row: false,
              hide: true,
              display: false,
            },
            {
              label: "体检医院",
              prop: "tjyy",
              align: "center",
              row: false,
              rules: [{
                required: true,
                message: "请输入体检医院",
                trigger: "blur"
              }]
            },
            {
              label: "体检日期",
              prop: "tjrq",
              align: "center",
              row: false,
              rules: [{
                required: true,
                message: "请输入体检日期",
                trigger: "blur"
              }]
            },



            {
              label: "下次体检时间",
              prop: "xctjsj",
              align: "center",
              row: false,
              rules: [{
                required: true,
                message: "请输入下次体检时间",
                trigger: "blur"
              }]
            },
            {
              label: "体检结论",
              prop: "tjjl",
              align: "center",
              row: false,
              hide: true,
              type: "textarea",
              span: 24,
              rules: [{
                required: true,
                message: "请输入体检结论",
                trigger: "blur"
              }]
            },

            {
              label: "体检结果",
              prop: "tjjg",
              align: "center",
              row: false,
              hide: true,
              type: "textarea",
              span: 24,
              rules: [{
                required: true,
                message: "请输入体检结果",
                trigger: "blur"
              }]
            },
            {
              label: "备注",
              prop: "bz",
              align: "center",
              type: "textarea",
              span: 24,
              hide: true,
              rules: [{
                message: "请输入备注",
                trigger: "blur"
              }]
            },

            {
              label: "企业",
              prop: "bladeDeptId",
              align: "center",
              row: false,
              hide: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
            },
            {
              label: "创建人",
              prop: "createUser",
              align: "center",
              row: false,
              hide: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
            },{
              label: "体检人员",
              prop: "tjry",
              align: "center",
              row: false,
              hide: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
            },
            {
              label: "创建部门",
              prop: "createDept",
              align: "center",
              row: false,
              hide: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
            },
            {
              label: "创建时间",
              prop: "createTime",
              align: "center",
              row: false,
              hide: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
            },
            {
              label: "修改人",
              prop: "updateUser",
              align: "center",
              row: false,
              hide: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
            },
            {
              label: "修改时间",
              prop: "updateTime",
              align: "center",
              row: false,
              hide: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
            },
          ]
        },
        data: []
      };
    },
    watch: {
      staffphysicalexamiRecordDialog(){
        if(this.staffphysicalexamiRecordDialog === true){
          this.initData();
        }
      }
    },
    computed: {
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    },

    mounted() {
      this.initData();
    },
    methods: {

      initData() {
        this.onLoad(this.page);
      },
      currentChange(currentPage){
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize){
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      rowDel(row) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(row.id);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
      },
      handleDelete() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
        }
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(this.ids);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$refs.crud.toggleSelection();
          });
      },


      // 获取历史列表
      onLoad(page, params = {}) {
        this.loading = true;
        this.query = {tjry: this.selectTJRYId};
        console.log(this.selectionList);
        getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          console.log(page)
          const resData = res.data.data;
          this.page.total = resData.total;
          this.data = resData.records;
          this.loading = false;
        });
      },

      // 确认历史
      confirmStaffphysicalexamiRecord() {
        this.$emit('confirmStaffphysicalexamiRecord');
      },

      // 关闭弹窗
      handleCloseStaffphysicalexamiRecord(done) {
        done();
        this.$emit('handleCloseStaffphysicalexamiRecord');
      }

    }
  };
</script>

<style>
</style>
